<template>
  <div class="numberplateInquiry">
    <c-title :hide="false" text="绑定车牌"></c-title>
    <div class="carBox">
      <div class="top">车牌号</div>
      <div class="car_lis">
        <template v-for="(item, index) in selectProvince">
          <div class="crile" :key="index" v-if="index == 2">·</div>
          <div class="proivesBtn" :class="selectInd == index ? 'sd' : ''" @click="provincesShowTap(index)" :key="index">
            <span>{{ item }}</span>
            <div class="cursor"></div>
          </div>
        </template>
      </div>
      <div class="radio_line">
        <van-radio-group v-model="licensePlate" direction="horizontal" @change="radioChange">
          <van-radio name="0" checked-color="#FE5E56">绿牌</van-radio>
          <van-radio name="1" checked-color="#FE5E56">蓝牌</van-radio>
          <van-radio name="2" checked-color="#FE5E56">黄牌</van-radio>
        </van-radio-group>
      </div>
      <div class="radio_line">
        <van-radio-group v-model="car_type" direction="horizontal">
          <van-radio name="0" checked-color="#FE5E56">汽车</van-radio>
          <van-radio name="1" checked-color="#FE5E56">摩托车</van-radio>
        </van-radio-group>
      </div>
      <car_number_keyboard @clickChild="clickChild" @delete="child_Delete" :ind="selectInd" :show="provincesShow" :keyboardType="keyboardType"></car_number_keyboard>

      <div class="bottom_btn" @click="toSearch">绑定车牌</div>
      <van-popup v-model="show" style="background: transparent;" :close-on-click-overlay="false">
        <div class="popup_box">
          <div class="title">绑定成功奖励</div>
          <div class="couponLis">
            <template v-if="info">
              <div class="lis" v-for="item in info" :key="item">
                <div class="lis_l">
                  <div class="lis_span" v-if="item.discount_type == 0">￥</div>
                  <div class="lis_txt van-ellipsis">{{ item.value }}</div>
                  <div class="lis_span_c" v-if="item.discount_type == 1">折</div>
                </div>
                <div class="lis_r">
                  <div class="lis_r_txt van-ellipsis">{{ item.title }}</div>
                  <div class="coupon van-ellipsis" v-if="item.desc">{{ item.desc }}</div>
                  <span class="small" v-if="item.name">{{ item.name }}</span>
                </div>
              </div>
            </template>
          </div>
        </div>
        <i class="iconfont icon-adsystem_icon_cancle" @click="closeBack"></i>
      </van-popup>
    </div>
  </div>
</template>
<script>
import car_number_keyboard from "../car-manage/components/car-number-keyboard.vue";
import base64_decode from "../../utils/base64_decode";

export default {
  data() {
    return {
      provincesShow: false,
      selectProvince: ["", "", "", "", "", "", "", ""],
      keyboardType: 1,
      licensePlate: "0",
      selectInd: null,
      radio: "0",
      car_type: "0",
      show: false,
      info: null
    };
  },
  watch: {
    listChange: function(nval, oval) {
      if (nval) {
        this.selectProvince = ["", "", "", "", "", "", "", ""];
        this.selectInd = 0;
      } else {
        this.selectProvince = ["", "", "", "", "", "", ""];
        this.selectInd = 0;
      }
    }
  },
  computed: {
    listChange() {
      const { radio, licensePlate } = this;
      console.log(licensePlate);
      if (radio == "0" && licensePlate == "0") {
        return true;
      } else {
        return false;
      }
    }
  },
  activated() {
    console.log(sessionStorage.getItem("yz_redirect"), "qqqqqqqqqqq", window._activePageURL);
  },
  methods: {
    closeBack() {
      this.show = false;
      let yz_redirect = sessionStorage.getItem("yz_redirect");
      console.log(sessionStorage.getItem("yz_redirect"), "qqqqqqqqqqq", window._activePageURL);
      window.location.href = window._activePageURL.indexOf('/carBind') > -1 ? base64_decode(yz_redirect) : window._activePageURL;
      // 回去触发绑定的页面
    },
    radioChange() {
      this.keyboardType = 1;
      this.selectInd = 0;
    },
    async toSearch() {
      let str = [...this.selectProvince].join("");
      if (this.fun.isTextEmpty(str)) {
        return this.$toast("请输入车牌号");
      }
      let json = {
        car_info: {
          license_no: str,
          license_colour: this.licensePlate,
          car_type: this.car_type
        }
      };
      let { data, msg, result } = await $http.post("plugin.car-manage.frontend.controllers.car.bind-car", json, "");
      if (result) {
        this.info = data;
        this.show = true;
      } else {
        this.$toast(msg);
      }
    },
    provincesShowTap(index) {
      this.provincesShow = true;
      this.selectInd = index;
      if (index == 0) {
        this.keyboardType = 1;
      } else if (index >= 1) {
        this.keyboardType = 2;
      }
    },
    clickChild(e) {
      this.$set(this.selectProvince, e.ind, e.key);
      if (e.ind < this.selectProvince.length - 1) {
        this.selectInd = e.ind + 1;
        if (this.selectInd == 0) {
          this.keyboardType = 1;
        } else if (this.selectInd > 0) {
          this.keyboardType = 2;
        }
      }
    },
    child_Delete(e) {
      this.$set(this.selectProvince, e.ind, "");
    }
  },
  components: { car_number_keyboard }
};
</script>
<style lang="scss" scoped>
.numberplateInquiry {
  .icon-adsystem_icon_cancle {
    font-size: 2rem;
    color: #d6d6dc;
  }
  .popup_box {
    width: 18.75rem;
    background: linear-gradient(348deg, #ff4753 0%, #ff9d72 100%);
    border-radius: 0.94rem 0.94rem 0.94rem 0.94rem;
    margin-bottom: 1rem;
    padding: 0 0.94rem;
    box-sizing: border-box;
    overflow: hidden;
    padding-bottom: 0.94rem;
    .title {
      font-weight: bold;
      font-size: 1.44rem;
      color: #ffffff;
      margin-bottom: 0.97rem;
      margin-top: 1.06rem;
    }
    .couponLis {
      height: 20rem;
      overflow-y: scroll;
      .lis {
        height: 3.47rem;
        background: #ffffff;
        border-radius: 0.63rem;
        margin-bottom: 0.63rem;
        display: flex;
        justify-content: space-between;
        position: relative;
        overflow: hidden;
        .small {
          font-size: 0.69rem;
          color: #6e6e79;
        }
        .lis_l {
          width: 5.88rem;
          height: 100%;
          flex-shrink: 0;
          position: relative;
          display: flex;
          align-items: center;
          justify-content: center;
          font-weight: bold;
          font-size: 1.5rem;
          color: #ec2b2b;
          .lis_span {
            font-size: 0.81rem;
            margin-top: 0.4rem;
          }
        }
        .lis_l::before {
          content: "";
          position: absolute;
          right: 0;
          top: 0.56rem;
          width: 1px;
          height: 2.24rem;
          border-right: 1px #999 dashed;
        }
        .lis_r {
          flex: 1;
          height: 100%;
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: flex-start;
          padding: 0.63rem;
          box-sizing: border-box;
          .lis_r_txt {
            font-weight: 500;
            font-size: 0.81rem;
            color: #00001c;
            line-height: 0.9rem;
          }
          .coupon {
            font-size: 0.75rem;
            color: #6e6e79;
            line-height: 0.9rem;
            margin-top: 0.53rem;
          }
        }
      }
      .lis::after {
        content: "";
        position: absolute;
        left: 5.58rem;
        width: 0.5rem;
        height: 0.5rem;
        border-radius: 50%;
        background: #ff635d;
        top: -0.2rem;
      }
      .lis::before {
        content: "";
        position: absolute;
        left: 5.58rem;
        width: 0.5rem;
        height: 0.5rem;
        border-radius: 50%;
        background: #ff635d;
        bottom: -0.2rem;
      }
      .lis:last-child {
        margin-bottom: 0;
      }
    }
  }
  .carBox {
    margin: 0.63rem;
    background: #ffffff;
    border-radius: 0.5rem;
    padding: 0.94rem 0.88rem;
    box-sizing: border-box;
    .radio_line {
      margin-top: 0.56rem;
    }
    .radio_line:last-child {
      margin-bottom: 2rem;
    }
    .top {
      font-size: 0.94rem;
      margin-bottom: 0.88rem;
      text-align: left;
    }
    .bottom_btn {
      height: 2.5rem;
      background: #f15353;
      border-radius: 1.28rem;
      margin-top: 2.19rem;
      line-height: 2.5rem;
      color: #ffffff;
      text-align: center;
      font-weight: 500;
      font-size: 0.94rem;
    }
  }
  .car_lis {
    display: flex;
    align-items: center;
    justify-content: space-around;

    .crile {
      font-size: 1rem;
      border: 1rem;
      font-weight: bold;
      margin: 0 0.63rem;
    }
    input,
    .proivesBtn {
      border: 0.03rem solid #d6d6dc;
      width: 2.19rem;
      height: 2.19rem;
      background: #ffffff;
      border-radius: 0.5rem;
      margin-right: 0.25rem;
      display: flex;
      justify-content: center;
      align-items: center;
      text-align: center;
    }
    .sd {
      border: 1px solid #0099ff;
      box-shadow: 0px 0px 10px #0099ff;
      position: relative;
      .cursor {
        width: 0.0625rem;
        height: 0.9375rem;
        background-color: #0099ff;
        animation: flashing 1.2s infinite steps(1, start);
      }
    }
    @keyframes flashing {
      0%,
      100% {
        background-color: #0099ff;
      }

      50% {
        background-color: transparent;
      }
    }
  }
}
</style>
